package su.NewFeatureType;

import su.Ner.NerDataSequence;
import iitb.CRF.DataSequence;
import iitb.Model.FeatureGenImpl;
import iitb.Model.FeatureImpl;
import iitb.Model.FeatureTypes;

public class CurrentCaseFeatures extends FeatureTypes {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	int stateId;
	String _case;
    String fname="CurrCase.";
	public static int maxFeatureNum=NerDataSequence.labelNum*2;
	
	public CurrentCaseFeatures(FeatureGenImpl fgen,int baseID) {
		super(fgen);
		this.baseId=baseID;
	}

	@Override
	public boolean hasNext() {
		if (stateId==-1)
			return false;
		return true;
	}

	@Override
	public void next(FeatureImpl f) {
		int ca=0;
		if(_case.equals("upper"))
			ca=1;
		//setFeatureIdentifier(baseId-(2*stateId+ca),stateId,fname+_case,f);
		f.strId.init(baseId-(2*stateId+ca),stateId,fname+_case);
		f.yend = stateId;
		f.ystart = -1;
		f.val = 1;
		stateId++;
		if(stateId==NerDataSequence.labelNum)
			stateId=-1;
	}

	@Override
	public boolean startScanFeaturesAt(DataSequence data, int prevPos, int pos) {
		
		char c=((String)data.x(pos)).charAt(0);
		if( ! Character.isLetter(c) ){
			stateId=-1;
			return false;
		}
		stateId=0;
		if(Character.isUpperCase(c))
			_case="upper";
		else
			_case="lower";
		return true;
	}
	
}
